package com.unohacha.qqj.fzdr.personal.model;

import com.unohacha.qqj.fzdr.common.bean.HttpResult;
import com.unohacha.qqj.fzdr.common.http.RetrofitManager;
import com.unohacha.qqj.fzdr.personal.presenter.IVerifyCode;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class VerifyCodeImpl {

    private IVerifyCode iVerifyCode;

    public VerifyCodeImpl(IVerifyCode iVerifyCode) {
        this.iVerifyCode = iVerifyCode;
    }

    // 发送验证码
    public void sendVerifyCode(String type, String mobile) {

        Call<HttpResult<String>> call = RetrofitManager.getInstance().getSMSMessage(type, mobile);
        call.enqueue(new Callback<HttpResult<String>>() {
            @Override
            public void onResponse(Call<HttpResult<String>> call, Response<HttpResult<String>> response) {
                String data = response.body().getData();
                if (data != null) {
                    iVerifyCode.sendVerifyCodeSuccess(data);
                } else {
                    iVerifyCode.sendVerifyCodeSuccess("");
                }
            }

            @Override
            public void onFailure(Call<HttpResult<String>> call, Throwable t) {

            }
        });
    }
}
